<template>
  <div>
    <div class="city_container">
      <header id="head_top">
        <span class="head_logo" @click="go">反</span>
        <span class="login">{{ this.$store.state.city.city.name }}</span>
        <a href="/">切换城市</a>
      </header>
      <form class="city_form">
        <div>
          <input
            class="city_input input_style"
            type="search"
            v-model="inputVml"
            placeholder="输入学校、商务楼、地址"
            required="required"
          />
        </div>
        <div>
          <div @click="submit" class="city_submit input_style">提交</div>
        </div>
      </form>
      <ul class="getpois_ul">
        <li v-for="A in poisList" @click="msite(A)">
          <h4 class="pois_name pois_name ellipsis">{{ A.name }}</h4>
          <p class="pois_address ellipsis">{{ A.address }}</p>
        </li>
      </ul>
      <header v-if="S" class="pois_search_history">搜索历史</header>
      <ul class="getpois_ul" v-if="S">
        <li v-for="A in $store.state.city.citypois">
          <h4 class="pois_name ellipsis">{{ A.name }}</h4>
          <p class="pois_address ellipsis">{{ A.address }}</p>
        </li>
      </ul>
      <footer v-if="S" class="clear_all_history" @click="clear">
        清空所有
      </footer>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ElmCity',

  data() {
    return {
      inputVml: '',
      poisList: [],
      S: true,
    };
  },

  mounted() {
    //   var a = localStorage.getItem('cityObj')
    console.log(this.$store.state.city.city.name);
  },

  methods: {
    clear() {
      this.$store.commit('del');
    },
    msite(A) {
      this.S = false;
      // console.log(A);
      this.$store.commit('historyList', A);
    },
    go() {
      this.$router.go(-1);
    },
    submit() {
      if (this.inputVml != '') {
        console.log(this.sinput);
        this.axios({
          url: 'http://elm.cangdu.org/v1/pois?',
          post: 'post',
          // headers: {
          //   Authorization: `Bearer ${localStorage.getItem("token")}`,
          // },
          params: {
            type: 'search',
            city_id: this.$store.state.city.city.id,
            keyword: this.inputVml,
          },
        }).then((res) => {
          if (res.data) {
            console.log(res.data);
            this.poisList = res.data;
          }
        });
      }
    },
  },
};
</script>

<style scoped lang="scss">
#head_top {
  position: absolute;
  top: 0;
  background-color: #3190e8;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 1.94rem;
  display: flex;
  justify-content: center;
  align-items: center;
  .head_logo {
    left: 0.2rem;
    font-weight: 400;
    font-size: 0.7rem;
    color: #fff;
    width: 2.3rem;
    height: 0.7rem;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
  .login {
    right: 6.55rem;
    font-size: 0.8rem;
    color: #fff;
    text-align: center;
    font-weight: 700;
  }
  a {
    right: 0.4rem;
    font-size: 0.6rem;
    color: #fff;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }
}
.city_container {
  padding-top: 2.35rem;
  .city_form {
    background-color: #fff;
    border-top: 1px solid #e4e4e4;
    border-bottom: 1px solid #e4e4e4;
    padding-top: 0.4rem;
    div {
      width: 90%;
      margin: 0 auto;
      text-align: center;
    }
    .city_input {
      border: 1px solid #e4e4e4;
      padding: 0 0.3rem;
      font-size: 0.65rem;
      color: #333;
    }
    .input_style {
      border-radius: 0.1rem;
      margin-bottom: 0.4rem;
      width: 100%;
      height: 1.4rem;
    }
    .city_submit {
      background-color: #3190e8;
      font-size: 0.65rem;
      color: #fff;
    }
  }
  .getpois_ul {
    background-color: #fff;
    border-top: 1px solid #e4e4e4;
    li {
      margin: 0 auto;
      padding-top: 0.65rem;
      border-bottom: 1px solid #e4e4e4;
      .pois_name {
        margin: 0 auto 0.35rem;
        width: 90%;
        font-size: 0.65rem;
        color: #333;
      }
      .ellipsis {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: left;
      }
      .pois_address {
        width: 90%;
        margin: 0 auto 0.55rem;
        font-size: 0.45rem;
        color: #999;
      }
    }
  }
}
.pois_search_history {
  border-top: 1px solid #e4e4e4;
  border-bottom: 1px solid #e4e4e4;
  padding-left: 0.5rem;
  font: 0.475rem/0.8rem Microsoft YaHei;
  text-align: left;
}
.clear_all_history {
  font-size: 0.7rem;
  color: #666;
  text-align: center;
  line-height: 2rem;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
}
</style>
